<form action="" id="home-slide" method="post" class="_ajaxSubmit">
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists" id="lists">
        <?php if($data):?>
            <?php foreach($data as $v):?>
                <div class="col-xs-12 col-md-12 col-lg-12 _data" style="margin-bottom: 10px">
                    <div class="col-md-3">
                        <img src="<?php echo $v['image'] ? cutUrl($v['image'],200,100) : '/statics/common/images/image.png'?>" data-src="<?php echo $v['image'] ? cutUrl($v['image'],200,100) : '/statics/common/images/image.png'?>"  data-toggle="tooltip" data-placement="top" title="建议上传200x100(px)的.jpg图片" width="140" height="70" class="thumb pull-right _thumb">
                    </div>
                    <?php

                        $selected = [
                            'go_category' => 'go_category',
                            'go_goods' => 'go_goods',
                            'go_special' => 'go_special',
                            'go_activity' => 'go_activity',
                            'go_page' => 'go_page',
                        ];

                    $$selected[$v['type']] = 'selected';



                    ?>
                    <div class="col-md-3" style="padding-top: 20px">
                        <select name="" class="form-control radius-none">
                            <option data-name="分类ID" <?php echo $go_category?> value="go_category">跳转到分类</option>
                            <option data-name="商品ID" <?php echo $go_goods?> value="go_goods">跳转到商品</option>
                            <option data-name="专题ID" <?php echo $go_special?> value="go_special">跳转到专题</option>
                            <option data-name="活动ID" <?php echo $go_activity?> value="go_activity">跳转到活动</option>
                            <option data-name="页面连接" <?php echo $go_page?> value="go_page">跳转到页面</option>
                        </select>
                    </div>
                    <div class="col-md-4" style="padding-top: 20px">
                        <div class="input-group">
                            <span class="input-group-addon radius-none">分类ID</span>
                            <input type="text"  class="form-control radius-none" value="<?php echo $v['type_val']?>">
                        </div>
                    </div>
                    <div class="col-md-2" style="padding-top: 20px">
                        <button type="button" class="btn btn-danger radius-none delete">删除</button>
                    </div>
                </div>
            <?php endforeach;?>
        <?php else:?>
            <div class="col-xs-12 col-md-12 col-lg-12 _data" style="margin-bottom: 10px">
            <div class="col-md-3">
                <img src="/statics/common/images/image.png"  data-toggle="tooltip" data-placement="top" title="建议上传200x100(px)的.jpg图片" width="140" height="70" class="thumb pull-right _thumb">
            </div>
            <div class="col-md-3" style="padding-top: 20px">
                <select name="" class="form-control radius-none">
                    <option data-name="分类ID" value="go_category">跳转到分类</option>
                    <option data-name="商品ID" value="go_goods">跳转到商品</option>
                    <option data-name="专题ID" value="go_special">跳转到专题</option>
                    <option data-name="活动ID" value="go_activity">跳转到活动</option>
                    <option data-name="页面连接" value="go_page">跳转到页面</option>
                </select>
            </div>
            <div class="col-md-4" style="padding-top: 20px">
                <div class="input-group">
                    <span class="input-group-addon radius-none">分类ID</span>
                    <input type="text"  class="form-control radius-none">
                </div>
            </div>
            <div class="col-md-2" style="padding-top: 20px">
                <button type="button" class="btn btn-danger radius-none delete">删除</button>
            </div>
        </div>
        <?php endif;?>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 lists text-right">
        <input type="submit" name="dosubmit" value="保存" class="btn btn-success radius-none">
        <input type="reset"  value="重置" class="btn btn-info radius-none">
        <input type="button" id="add-one" value="添加一栏" class="btn btn-default radius-none">
    </div>
</form>
<script>
    //储存节点对象
    var $setting = {}

    $(function(){

        Admin.upload('._thumb',false,function(objects){

            $setting.images = objects;

        });

        $('#home-slide').undelegate('select','change');
        $('#home-slide').delegate('select','change',function(){

            var _this = $(this);

            var name = $('option:selected',_this).data('name');

            _this
                    .parent()
                    .next()
                    .children()
                    .children('span')
                    .text(name)


        });

        $('[data-toggle="tooltip"]').tooltip();

        $('#add-one').unbind('click');
        $('#add-one').click(function(){

            var str = '\
                    <div class="col-xs-12 col-md-12 col-lg-12 _data" style="margin-bottom: 10px">\
                        <div class="col-md-3">\
                            <img src="/statics/common/images/image.png"  data-toggle="tooltip" data-placement="top" title="建议上传200x100(px)的.jpg图片" width="140" height="70" class="thumb pull-right _thumb">\
                        </div>\
                        <div class="col-md-3" style="padding-top: 20px">\
                            <select name="" class="form-control radius-none">\
                                <option data-name="分类ID" value="go_category">跳转到分类</option>\
                                <option data-name="商品ID" value="go_goods">跳转到商品</option>\
                                <option data-name="专题ID" value="go_special">跳转到专题</option>\
                                <option data-name="活动ID" value="go_activity">跳转到活动</option>\
                                <option data-name="页面连接" value="go_page">跳转到页面</option>\
                            </select>\
                        </div>\
                        <div class="col-md-4" style="padding-top: 20px">\
                            <div class="input-group">\
                                <span class="input-group-addon radius-none">分类ID</span>\
                                <input type="text"  class="form-control radius-none">\
                            </div>\
                        </div>\
                        <div class="col-md-2" style="padding-top: 20px">\
                            <button type="button" class="btn btn-danger radius-none delete">删除</button>\
                        </div>\
                    </div>\
                    ';
            $('#lists').append(str);

            $('[data-toggle="tooltip"]').tooltip();

        });


        $('#home-slide').undelegate('.delete','click');
        $('#home-slide').delegate('.delete','click',function(){

            var _this = $(this);

            layer.msg('确定删除吗?', {
                time: 20000, //20s后自动关闭
                btn: ['删除', '关闭'],
                yes:function(index){

                    layer.close(index);

                    _this
                            .parent()
                            .parent()
                            .fadeOut(200,function(){

                                $(this).remove();

                            })

                }
            });
        });

        //提交数据
        $('form#home-slide').submit(function(){

            var _this = $(this);

            var data = [];

            $('._data',_this).each(function(){

                var slide_info = {};

                slide_info.image = $('img',$(this)).data('src');
                slide_info.type = $('select option:checked',$(this)).val();
                slide_info.type_val = $('input',$(this)).val();

                data.push(slide_info);

            });

            //console.log(data)
            //return false;

            $.post("<?php echo U('Admin/Setting/Index/setSlide')?>",{'data':data},function(result){

                showMessage(result.msg,result.code,'','',2000);

            });

            return false;
        })

    });


    //图片上传回调
    function getImageSrc(_this){

        $setting.images.attr('src',cutUrl(_this[0],200,100));
        $setting.images.data('src',_this[0]);

    }
</script>